package com.dd.cloud.user.DTO.km;

import cn.hutool.core.codec.Base64;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAliasType;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.DomDriver;
import lombok.Data;

/**
 * 取消处方参数-康美药房
 *
 * @author Lx
 * @version 1.0
 */
@Data
@XStreamAliasType("orderInfo")
public class CancelPresBodyDTO {
    /**
     * 请求头
     */
    @XStreamAlias("head")
    private SendPresHeadDTO head;

    /**
     * 请求数据
     */
    @XStreamAlias("data")
    private Data data;

    @lombok.Data
    public static class Data {
        /**
         * 取消操作人	必须
         */
        private String oper_name;

        /**
         * 取消原因	必须
         */
        private String reason;

        /**
         * 订单id	必须
         */
        private String order_id;
    }

    /**
     * 转换xml
     */
    public String toSoapXml() {
        XStream xStream = new XStream(new DomDriver("UTF-8", new NoNameCoder()));
        xStream.autodetectAnnotations(true);
        xStream.omitField(SendPresHeadDTO.class, "methodName");
        String xml = xStream.toXML(this);
        xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + xml;
        System.out.println("xml:\n" + xml);
        return "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                "<soap:Body><ns1:saveCancelOrder xmlns:ns1=\"http://factory.service.cxf.kangmei.com/\"><request>"
                + Base64.encode(xml) +
                "</request></ns1:saveCancelOrder></soap:Body></soap:Envelope>";
    }
}
